# =========== base ===========
FROM registry.cn-hangzhou.aliyuncs.com/yoyosoft/dotnet_aspnet_gdi_fontconfig:5.0 AS base
WORKDIR /app
EXPOSE 80
# 设置ssl
RUN sed -i 's/TLSv1.2/TLSv1.0/g' /etc/ssl/openssl.cnf
# 设定容器时区为上海
ENV TZ Asia/Shanghai
RUN ln -fs /usr/share/zoneinfo/${TZ} /etc/localtime \
    && echo ${TZ} > /etc/timezone


# =========== build base ===========
FROM registry.cn-hangzhou.aliyuncs.com/yoyosoft/dotnet_sdk:5.0 AS build
WORKDIR /source-code
COPY . .


# =========== publish ===========
FROM build AS publish
WORKDIR "/source-code/src/aspnet-core/src/GCT.Foundation.Template.Migrator"
RUN dotnet restore --ignore-failed-sources
RUN dotnet publish --no-restore "GCT.Foundation.Template.Migrator.csproj"  -c Release -o /app/publish


# =========== final ===========
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .


ENV WAITHOST=localhost WAITPORT=1433
RUN chmod +x wait-for-it.sh

ENTRYPOINT ./wait-for-it.sh $WAITHOST:$WAITPORT --timeout=0 \
    && exec dotnet GCT.Foundation.Template.Migrator.dll -q --listener
